package com.kznnc.data_structure.sort;

/**
 * @Description 递归算法 An = An-1
 * @Author houchenkai
 * @Created Date: 2021/6/23 18:21
 * @ClassName
 */
public class RecursiveDemo {


    public static int getFib(int n) {
        if (n <= 2) {
            return 1;
        } else {
            return getFib(n - 1) + getFib(n - 2);
        }


    }

    public static int two(int n) {
        int a = 0;
        int b = 1;
        int c = 0;
        for (int i = 1; i < n; i++) {
            c = b + a;
            a = b;
            b = c;
        }
        return c;
    }


    public static void main(String[] args) {

        int fib = getFib(8);
        System.out.println(fib);
        System.out.println(two(8));

    }

}
